def countTypesTable = [ : ]

count = {ln, type, categorizationFunction ->
        def c = categorizationFunction(ln)
        def table = countTypesTable[type]
        if(!table){
                table = [:]
                countTypesTable[type]=table
        }
        if(c)
        {
                table[c]=(table[c]?:0)+1
        }
}

countResult= {type ->
       def res = countTypesTable[type] 
       def total = 0
       res.each{total+=it.value}
       res["total"]=total
       return res
}

printUnknownRequests = { ln, categorizationFunction ->
        def c = categorizationFunction(ln)
        if (c == "UNKNOWN_REQUEST")
                println ln
}

def accumulateTypesTable = [ : ]
accumulate = {ln, type, numberFunction ->
        def n = numberFunction(ln)
        if(!n) return
        accumulateTypesTable[type] = n + accumulateTypesTable[type]?:0
}
accumulateResult = {type ->
        return accumulateTypesTable[type]
}
